package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ArticleLabel;
import com.ruoyi.system.service.IArticleLabelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 查询关联Controller
 * 
 * @author ruoyi
 * @date 2024-03-13
 */
@RestController
@RequestMapping("/system/al")
public class ArticleLabelController extends BaseController
{
    @Autowired
    private IArticleLabelService articleLabelService;

    /**
     * 查询查询关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:al:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArticleLabel articleLabel)
    {
        startPage();
        List<ArticleLabel> list = articleLabelService.selectArticleLabelList(articleLabel);
        return getDataTable(list);
    }

    /**
     * 导出查询关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:al:export')")
    @Log(title = "查询关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArticleLabel articleLabel)
    {
        List<ArticleLabel> list = articleLabelService.selectArticleLabelList(articleLabel);
        ExcelUtil<ArticleLabel> util = new ExcelUtil<ArticleLabel>(ArticleLabel.class);
        util.exportExcel(response, list, "查询关联数据");
    }

    /**
     * 获取查询关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:al:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(articleLabelService.selectArticleLabelById(id));
    }

    /**
     * 新增查询关联
     */
    @PreAuthorize("@ss.hasPermi('system:al:add')")
    @Log(title = "查询关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArticleLabel articleLabel)
    {
        return toAjax(articleLabelService.insertArticleLabel(articleLabel));
    }
    
    /**
     * 批量新增关联
     */
    @PreAuthorize("@ss.hasPermi('system:al:add')")
    @PostMapping("/batchInsert")
    public AjaxResult batchInsert(@RequestBody List<ArticleLabel> articleLabel)
    {
        return toAjax(articleLabelService.batchInsert(articleLabel));
    }
    
    /**
     * 修改查询关联
     */
    @PreAuthorize("@ss.hasPermi('system:al:edit')")
    @Log(title = "查询关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArticleLabel articleLabel)
    {
        return toAjax(articleLabelService.updateArticleLabel(articleLabel));
    }

    /**
     * 删除查询关联
     */
    @PreAuthorize("@ss.hasPermi('system:al:remove')")
    @Log(title = "查询关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(articleLabelService.deleteArticleLabelByIds(ids));
    }
    
    @PreAuthorize("@ss.hasPermi('system:al:remove')")
	@DeleteMapping("/removeByArticleId")
    public AjaxResult removeByArticleId(@RequestBody Long articleId)
    {
        return toAjax(articleLabelService.deleteArticleLabelByArticleId(articleId));
    }
}
